package PseudoRandomNumberAlgorithm;

public class MTTest {

    private static class MTTestData {
        private String seed;
        private final String[] output = new String[10];

        public MTTestData(String seed, String[] output) {
            this.seed = seed;
            for (int i = 0; i < 10; i++) {
                this.output[i] = output[i];
            }
        }

        public String getOutput(int index) {
            return output[index];
        }
    }

    public static void main(String[] args) {
        primaryTest();
    }

    private static void primaryTest() {
        MTTestData[] testData = new MTTestData[3];
        testData[0] = new MTTestData("0", new String[]{
                "2357136044", "2546248239", "3071714933", "3626093760",
                "2588848963", "3684848379", "2340255427", "3638918503",
                "1819583497", "2678185683"
        });

        testData[1] = new MTTestData("1234", new String[]{
                "822569775", "2137449171", "2671936806", "3512589365",
                "1880026316", "2629000564", "3373089432", "3312965625",
                "3349970575", "3696548529"
        });

        testData[2] = new MTTestData("65535", new String[]{
                "830396586", "4100689589", "1135755905", "3844769943",
                "4124698092", "3951842709", "2653898755", "3583752502",
                "3875248359", "3043937779"
        });

        for (MTTestData data : testData) {
            boolean flag = true;
            MersenneTwist mt19937 = new MersenneTwist(data.seed);
            for (int i = 0; i < 10; i++) {
                String extract = mt19937.extract().toString();
                flag = extract.equals(data.getOutput(i));
                if (!flag) {
                    System.out.printf("种子%s的第%d轮不对！%n", data.seed, i);
                    break;
                }
            }
            if (flag) {
                System.out.printf("种子%s的测试通过！%n", data.seed);
            } else {
                System.out.printf("种子%s的测试不通过！%n", data.seed);
            }
        }


    }

}
